//
// Created by Administrator on 2021/11/10.
//

#ifndef LEARNREALTIMERENDERING_CAMERA_H
#define LEARNREALTIMERENDERING_CAMERA_H

#include "Geometry.hpp"
#include "Transform.h"

class Camera
{
public:
    Camera() = default;
    ~Camera() = default;

    void Setup(
            float aspect,
            float fov,
            float near,
            float far);

    const Mat4x4f& cameraToWorldMatrix();
    const Mat4x4f& worldToCameraMatrix();
    const Mat4x4f& projectionMatrix();
    const Transform& transform() const { return m_transform; }
    Transform& transform() { return m_transform; }

private:
    void BuildCameraMatrix();
    void BuildProjectionMatrix();
    void BuildCanvas();

    struct Canvas
    {
        float l, r, t, b;
    };

    Mat4x4f m_CameraToWorldMatrix;
    Mat4x4f m_WorldToCameraMatrix;
    Mat4x4f m_ProjectionMatrix;
    Canvas m_Canvas;
    float m_Aspect;
    float m_Fov;
    float m_Near;
    float m_Far;

    Transform m_transform;

    bool m_CameraDirty = false;
    bool m_ProjDirty = false;
};

#endif //LEARNREALTIMERENDERING_CAMERA_H
